<?php
//  This file is part of EkkinCMS.
//
//  EkkinCMS is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  EkkinCMS is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with EkkinCMS.  If not, see <http://www.gnu.org/licenses/>.

$r = $db->query( "SELECT * FROM config" );
//print_r($r);
foreach ($r as $key){
    if ($key[name] == "site_template"){
        $old_site_template = $key[value];
    }
    if ($key[name] == "site_title"){
        $old_site_title = $key[value];
    }
    if ($key[name] == "site_image"){
        $old_site_image = $key[value];
    }
    if ($key[name] == "site_mail"){
        $old_site_mail = $key[value];
    }
    if ($key[name] == "site_gtrans"){
        $old_site_gtrans = $key[value];
    }
}
$new_site_template = $_POST["site_template"];
$new_site_title = $_POST["site_title"];
$new_site_image = $_POST["site_image"];
$new_site_mail = $_POST["site_mail"];
$new_site_gtrans = $_POST["site_gtrans"];

if ($new_site_gtrans == "") $new_site_gtrans = "false";

function config_do_query($new_value, $name, $old_value){
    global $db;
    if ($old_value == "") {
        $query = "
        INSERT INTO config (name, value) VALUES ( \"$name\", \"$new_value\" );
        ";
    } else {
        $query = "
    UPDATE config
        SET
            value = '$new_value'
    WHERE
        name = '$name'
        ";
    }

    echo $query;
    $db->exec($query);
}
config_do_query($new_site_title, 'site_title', $old_site_title);
config_do_query($new_site_template, 'site_template', $old_site_template);
config_do_query($new_site_image, 'site_image', $old_site_image);
config_do_query($new_site_mail, 'site_mail', $old_site_mail);
config_do_query($new_site_gtrans, 'site_gtrans', $old_site_gtrans);

$link = rtrim(construct_link(array("action")), "&");

echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$link\">";
die();

?>
